<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="../../configure.js"></script>
    
    
</head>
<body style="background-color: #F5F6F7">
<div class="container" style="background-color:white;margin-top: 20px">
    <form id="form" style="margin:10px 0px 10px">
        <span style="font-size:larger;color: black">修改快递员</span>
        <hr style="border: black 1px solid">
        <div class="form-group">
            <label for="courierPhone">电话号</label>
            <input id="courierPhone" type="text" class="form-control" name="courierPhone" id="courierPhone" placeholder="请输入电话号">
        </div>
        <button id="find"  type="button" class="btn btn-danger form-control ">查询</button>
        <div id="success" >
            <div class="form-group">
                <label for="courierName">姓名</label>
                <input type="text" class="form-control" name="courierName" id="courierName" placeholder="请输入姓名">
            </div>
            <div data-toggle="distpicker" class="form-group">
                <label>地址 :</label>
                <select name="courierProvince">
                    <option id="courierProvince"></option>
                </select>
                <select  name="courierCity">
                    <option id="courierCity"></option>
                </select>
                <select  name="courierArea">
                    <option id="courierArea"></option>
                </select>
            </div>
            <div class="form-group">
                <label>性别 :</label>
                <label class="radio-inline">
                    <input id="male" type="radio" name="sex" value="man">男
                </label>
                <label class="radio-inline">
                    <input id="female" type="radio" name="sex" value="woman">女
                </label>
            </div>
            <div class="form-group">
                <label for="IdCard">身份证号</label>
                <input type="text" class="form-control" name="IdCard" id="IdCard" placeholder="请输入身份证号">
            </div>
            <div class="form-group">
                <label for="siteId">所属站点ID</label>
                <input type="text" class="form-control" name="siteId" id="siteId" placeholder="请输入所属站点ID">
            </div>
            
            <button id="update" type="submit" class="btn btn-danger form-control ">修改</button>
        </div>
    </form>
</div>
<script src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/distpicker.data.js"></script>
<script src="../js/distpicker.js"></script>
<script src="../layer/layer.js"></script>
<script>
    $(function(){
        $("#male").click(function(){
            $("#male").attr("checked",true);
            $("#female").attr("checked",false);
        })

        $("#female").click(function(){
            $("#male").attr("checked",false);
            $("#female").attr("checked",true);
        })
        $("#success").hide();
        $("#find").click(function(){
            
            let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
            let courierPhone = $("#courierPhone").val();
            if (courierPhone=="") {
                layer.msg("手机号码不能为空");
                return false
            }else{
                if (!phoneReg.test(courierPhone)) {
                    layer.msg("手机号格式不正确");
                    return false
                }
            }  
            $.getJSON(url+"/admin/adminSelectCourier",{courierPhone:courierPhone},function(data){
                console.log(data)
                layer.msg(data.message);
                if(data.message == "查询成功"){
                    $("#success").show();
                    $("#find").hide();
                    $("#courierPassword").val("");
                    $("#IdCard").val(data.data[0].idCard);
                    $("#courierName").val(data.data[0].courierName);
                    $("#siteId").val(data.data[0].siteId);

                    $("#courierProvince").text(data.data[0].courierProvince);
                    console.log(data.data[0].courierProvince)
                    console.log(data.data[0].courierCity)
                    console.log(data.data[0].courierArea)
                    $("#courierCity").text(data.data[0].courierCity);
                    $("#courierArea").text(data.data[0].courierArea);
                }
               
            })
        });

        $("#form").submit(function(){

            var sex =""
            if($("#male").attr("checked")){
                var sex ="男"
            }else if($("#female").attr("checked")) {
                var sex ="女"
            }
            if (sex==null || sex=="") {
                layer.msg("请选择性别")
                return false
            }

            let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
            let courierPhone = $("#courierPhone").val();
            if (courierPhone=="") {
                layer.msg("手机号码不能为空");
                return false
            }else{
                if (!phoneReg.test(courierPhone)) {
                    layer.msg("手机号格式不正确");
                    return false
                }
            }   
            let courierName = $("#courierName").val();
            if (courierName=="") {
                layer.msg("姓名不能为空")
                return false
            } 
            let courierNum = $("#courierNum").val();
            if (courierNum=="") {
                layer.msg("快递编号不能为空")
                return false
            } 

            let IdCard = $("#IdCard").val();
            let IdReg = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

            if (IdCard=="") {
                layer.msg("身份证号不能为空")
                return false
            }else{
                if(!IdReg.test(IdCard)){
                    layer.msg("身份证号格式不正确");
                    return false
                }  
            }
            let siteId = $("#siteId").val();
            if (siteId=="") {
                layer.msg("所属站点不能为空")
                return false
            } 
            $.post(url+"/admin/adminUpdateCourier",{
                courierNum:courierNum,
                courierPhone:courierPhone,
                courierName:courierName,
                IdCard:IdCard,
                siteId:siteId,
                sex:sex
            },function(data){
                //layer.msg(data.data.message);
                console.log(data)
                if(data.code == 1){
                    //录入成功
                    layer.msg("修改成功");
                    $("input").val("");
                    // $("input:eq(1)").val("顺丰速运");
                }else{
                    layer.msg("修改失败");
                    //录入失败
                }
            });
            return false
        });
    });
</script>


</body>
</html>